package com.example.administrator.zhongyichou.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.zhongyichou.Bean.BaseEventBean;
import com.example.administrator.zhongyichou.R;
import com.example.administrator.zhongyichou.base.BaseActivity;
import com.example.administrator.zhongyichou.base.MyApplication;
import com.example.administrator.zhongyichou.config.Constants;
import com.example.administrator.zhongyichou.help.DateUtils;
import com.example.administrator.zhongyichou.net.NetConfig;
import com.example.administrator.zhongyichou.net.core.HttpLoader;
import com.example.administrator.zhongyichou.net.core.RequestHttpLoader;
import com.example.administrator.zhongyichou.net.protocol.InformationAuditProtocol;
import com.example.administrator.zhongyichou.view.HeaderView;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by lichenyu on 2017/11/24.
 * 描述：信息审核
 */

public class InformationAuditActivity extends BaseActivity<InformationAuditProtocol> {
    @BindView(R.id.headerview)
    HeaderView headerview;
    @BindView(R.id.img1)
    ImageView img1;
    @BindView(R.id.view1)
    View view1;
    @BindView(R.id.txt_title1)
    TextView txtTitle1;
    @BindView(R.id.txt_time1)
    TextView txtTime1;
    @BindView(R.id.view2)
    View view2;
    @BindView(R.id.img2)
    ImageView img2;
    @BindView(R.id.txt_title2)
    TextView txtTitle2;
    @BindView(R.id.txt_content2)
    TextView txtContent2;
    @BindView(R.id.txt_time2)
    TextView txtTime2;
    @BindView(R.id.btn1)
    Button btn1;
    @BindView(R.id.txt_empty)
    TextView txtEmpty;
    @BindView(R.id.txt_empty1)
    TextView txtEmpty1;
    @BindView(R.id.img3)
    ImageView img3;
    @BindView(R.id.view3)
    View view3;
    @BindView(R.id.txt_title3)
    TextView txtTitle3;
    @BindView(R.id.txt_time3)
    TextView txtTime3;
    @BindView(R.id.view4)
    View view4;
    @BindView(R.id.img4)
    ImageView img4;
    @BindView(R.id.txt_title_4)
    TextView txtTitle4;
    @BindView(R.id.txt_content4)
    TextView txtContent4;
    @BindView(R.id.txt_time4)
    TextView txtTime4;
    @BindView(R.id.btn2)
    Button btn2;
    @BindView(R.id.ll_content)
    LinearLayout llContent;
    @BindView(R.id.ll_content1)
    LinearLayout llContent1;
    private String infoID;
    private InformationAuditProtocol mGsonBaseProtocal;

    @Override
    protected void init() {
        ButterKnife.bind(this);
        initHead();
    }

    @Override
    protected void responseData(InformationAuditProtocol mGsonBaseProtocal) {
        this.mGsonBaseProtocal = mGsonBaseProtocal;
        if (mGsonBaseProtocal.getData().getSupply_patient().getInfo_type() == 0) {
            txtEmpty.setVisibility(View.VISIBLE);
            llContent.setVisibility(View.GONE);
            btn1.setText("立即补齐");
        } else {
            txtEmpty.setVisibility(View.GONE);
            llContent.setVisibility(View.VISIBLE);
            txtTime1.setText(DateUtils.stampToDate(mGsonBaseProtocal.getData().getSupply_patient().getCreate_time()));
            txtTime2.setText(DateUtils.stampToDate(mGsonBaseProtocal.getData().getSupply_patient().getAudit_time()));
            txtContent2.setText(mGsonBaseProtocal.getData().getSupply_patient().getRefuse_reason());
            switch (mGsonBaseProtocal.getData().getSupply_patient().getPatient_verify()) {
                case "0":
                    txtTitle2.setTextColor(getResources().getColor(R.color.black_text9));
                    txtTitle2.setText("信息审核中");
                    txtContent2.setVisibility(View.GONE);
                    txtTime2.setVisibility(View.GONE);
                    btn1.setVisibility(View.GONE);
                    view2.setBackgroundColor(getResources().getColor(R.color.black_text9));
                    img2.setImageResource(R.mipmap.state_icon_audit_circle);
                    break;
                case "1":
                    txtTitle2.setTextColor(getResources().getColor(R.color.red1));
                    txtTitle2.setText("信息审核未通过");
                    txtContent2.setTextColor(getResources().getColor(R.color.red1));
                    txtContent2.setVisibility(View.VISIBLE);
                    txtTime2.setVisibility(View.VISIBLE);
                    btn1.setVisibility(View.VISIBLE);
                    btn1.setText("重新验证");
                    view2.setBackgroundColor(getResources().getColor(R.color.red1));
                    img2.setImageResource(R.mipmap.state_icon_notpass_circle);
                    break;
                case "2":
                    txtTitle2.setTextColor(getResources().getColor(R.color.appColor));
                    txtTitle2.setText("已通过");
                    txtContent2.setVisibility(View.GONE);
                    txtTime2.setVisibility(View.VISIBLE);
                    btn1.setVisibility(View.GONE);
                    btn1.setText("查看详情");
                    view2.setBackgroundColor(getResources().getColor(R.color.appColor));
                    img2.setImageResource(R.mipmap.state_icon_pass_circle);
                    break;
            }

        }
        if (mGsonBaseProtocal.getData().getSupply_bank().getInfo_type() == 0) {
            txtEmpty1.setVisibility(View.VISIBLE);
            llContent1.setVisibility(View.GONE);
            btn2.setText("立即补齐");
        } else {
            txtEmpty1.setVisibility(View.GONE);
            llContent1.setVisibility(View.VISIBLE);
            txtTime3.setText(DateUtils.stampToDate(mGsonBaseProtocal.getData().getSupply_bank().getCreate_time()));
            txtTime4.setText(DateUtils.stampToDate(mGsonBaseProtocal.getData().getSupply_bank().getAudit_time()));
            txtContent4.setText(mGsonBaseProtocal.getData().getSupply_bank().getRefuse_reason());
            switch (mGsonBaseProtocal.getData().getSupply_bank().getPatient_verify()) {
                case "0":
                    txtTitle4.setTextColor(getResources().getColor(R.color.black_text9));
                    txtTitle4.setText("信息审核中");
                    txtContent4.setVisibility(View.GONE);
                    txtTime4.setVisibility(View.GONE);
                    btn2.setVisibility(View.GONE);
                    view4.setBackgroundColor(getResources().getColor(R.color.black_text9));
                    img4.setImageResource(R.mipmap.state_icon_audit_circle);
                    break;
                case "1":
                    txtTitle4.setTextColor(getResources().getColor(R.color.red1));
                    txtTitle4.setText("信息审核未通过");
                    txtContent4.setTextColor(getResources().getColor(R.color.red1));
                    txtContent4.setVisibility(View.VISIBLE);
                    txtTime4.setVisibility(View.VISIBLE);
                    btn2.setVisibility(View.VISIBLE);
                    btn2.setText("重新验证");
                    view4.setBackgroundColor(getResources().getColor(R.color.red1));
                    img4.setImageResource(R.mipmap.state_icon_notpass_circle);
                    break;
                case "2":
                    txtTitle4.setTextColor(getResources().getColor(R.color.appColor));
                    txtTitle4.setText("已通过");
                    txtContent4.setVisibility(View.GONE);
                    txtTime4.setVisibility(View.VISIBLE);
                    btn2.setVisibility(View.GONE);
                    btn2.setText("查看详情");
                    view4.setBackgroundColor(getResources().getColor(R.color.appColor));
                    img4.setImageResource(R.mipmap.state_icon_pass_circle);
                    break;
            }
        }
    }

    @Override
    protected HttpLoader initHttpLoader() {
        infoID = getIntent().getStringExtra("info_id");
        RequestHttpLoader requestHttpLoader = new RequestHttpLoader(InformationAuditProtocol.class);
        Map map = new HashMap();
        map.put("user_id", MyApplication.getUserID());
        map.put("info_id", infoID);
        requestHttpLoader.setParams(NetConfig.RAISE_STATUS, map);
        return requestHttpLoader;
    }

    @Override
    protected boolean isRequestData() {
        return true;
    }

    @Override
    protected int initContentView() {
        return R.layout.information_audit_activity;
    }

    @Override
    public boolean onEventBus(BaseEventBean baseEventBean) {
        if (baseEventBean.code == Constants.TYPE_1 || baseEventBean.code == Constants.TYPE_2) {
            requestData();
        }
        return false;
    }

    private void initHead() {
        headerview.setTitle("审核信息");
        headerview.bindOnclickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case HeaderView.LEFT:
                        finish();
                        break;
                }
            }
        });
    }

    @OnClick({R.id.btn1, R.id.btn2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn1:
                if (mGsonBaseProtocal.getData().getSupply_patient().getInfo_type() == 0) {
                    Intent intent1 = new Intent(this, ReplenishmentDiseaseInformationActivity.class);
                    intent1.putExtra("intentType", 1);
                    intent1.putExtra("info_id", mGsonBaseProtocal.getData().getInfo_id());
                    startActivity(intent1);
                } else if (mGsonBaseProtocal.getData().getSupply_patient().getPatient_verify().equals("1")) {//审核未通过编辑资料
                    Intent intent1 = new Intent(this, ReplenishmentDiseaseInformationActivity.class);
//                    intent1.putExtra("intentType", 2);
                    intent1.putExtra("intentType", 1);
                    intent1.putExtra("info_id", mGsonBaseProtocal.getData().getInfo_id());
                    startActivity(intent1);
                }
                break;
            case R.id.btn2:
                if (mGsonBaseProtocal.getData().getSupply_bank().getInfo_type() == 0) {
                    Intent intent2 = new Intent(this, ReplenishmentDiseaseInformationTwoActivity.class);
                    intent2.putExtra("info_id", mGsonBaseProtocal.getData().getInfo_id());
                    startActivity(intent2);
                } else if (mGsonBaseProtocal.getData().getSupply_bank().getPatient_verify().equals("1")) {//审核未通过时重新编辑银行卡
                    Intent intent2 = new Intent(this, ReplenishmentDiseaseInformationTwoActivity.class);
                    intent2.putExtra("info_id", mGsonBaseProtocal.getData().getInfo_id());
                    intent2.putExtra("intentType", 1);
                    startActivity(intent2);
                }
                break;
        }
    }
}
